Test Setup Failed
Push — master ( 8ee19e...25278d )
by recca
05:07 queued 46s
created

loading.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 10
rs 9.4285
c 3
b 0
f 0
1
'use strict';
2
3
export default class Loading {
4
    constructor(term) {
5
        this.$term = term;
6
        Object.assign(this, {
7
            anim: ['/', '|', '\\', '-'],
8
            prompt: null,
9
            delay: 50,
10
            intervalId: null,
11
            counter: 0
12
        });
13
    }
14
15
    show() {
16
        this.counter++;
17
        this.$term.disable();
18
        this.prompt = this.$term.get_prompt();
19
        let i = 0;
20
        this.intervalId = setInterval(() => {
21
            this.$term.set_prompt(this.anim[i++]);
22
            if (i > this.anim.length - 1) {
23
                i = 0;
24
            }
25
        }, this.delay);
26
    }
27
28
    hide() {
29
        this.counter--;
30
        if (this.counter <= 0) {
31
            clearInterval(this.intervalId);
32
            this.$term.enable();
33
            this.$term.set_prompt(this.prompt);
34
            this.counter = 0;
35
        }
36
    }
37
}
38